import 'base_model.dart';

/// 推荐视频模型
class RecommendedVideo implements BaseModel {
  final int? id;
  final String description; // 视频描述
  final String? thumbnailUrl; // 封面图片地址
  final String videoUrl; // 视频地址
  final int likeCount; // 点赞数
  final int favoriteCount; // 收藏数

  RecommendedVideo({
    this.id,
    required this.description,
    this.thumbnailUrl,
    required this.videoUrl,
    this.likeCount = 0,
    this.favoriteCount = 0,
  });

  // 从JSON构造
  factory RecommendedVideo.fromJson(Map<String, dynamic> json) {
    return RecommendedVideo(
      id: json['id'],
      description: json['description'] ?? 'No Description',
      thumbnailUrl: json['thumbnail_url'],
      videoUrl: json['video_url'] ?? '',
      likeCount: json['like_count'] ?? 0,
      favoriteCount: json['favorite_count'] ?? 0,
    );
  }

  // 从数据库Map构造
  factory RecommendedVideo.fromMap(Map<String, dynamic> map) {
    return RecommendedVideo.fromJson(map);
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      if (id != null) 'id': id,
      'description': description,
      'thumbnail_url': thumbnailUrl,
      'video_url': videoUrl,
      'like_count': likeCount,
      'favorite_count': favoriteCount,
    };
  }

  // 转换为Map (数据库存储)
  Map<String, dynamic> toMap() {
    return toJson();
  }

  // 创建副本但修改部分属性
  RecommendedVideo copyWith({
    int? id,
    String? description,
    String? thumbnailUrl,
    String? videoUrl,
    int? likeCount,
    int? favoriteCount,
  }) {
    return RecommendedVideo(
      id: id ?? this.id,
      description: description ?? this.description,
      thumbnailUrl: thumbnailUrl ?? this.thumbnailUrl,
      videoUrl: videoUrl ?? this.videoUrl,
      likeCount: likeCount ?? this.likeCount,
      favoriteCount: favoriteCount ?? this.favoriteCount,
    );
  }
}
